package com.itheima.collections;/*
 *@author wenqh
 *@date 2024/4/19 9:57
 *@Description
 */

import java.util.*;

public class Map_test {

    public static void main(String[] args) {
        Map<Integer,String> hashMap = new HashMap<>();//hash表支持空值
        hashMap.put(null,"5");
        hashMap.put(1,"3");
        hashMap.put(2,"4");
        hashMap.put(3,"6");
        //遍历key
        Set<Integer> integers = hashMap.keySet();
        for (Integer num:integers){
            System.out.println(hashMap.get(num));
        }
        System.out.println("---------------遍历value-----------------");
        //遍历value
        Collection<String> values = hashMap.values();
        for (String value:values){
            System.out.println(value);
        }
        System.out.println("--------------遍历key-value的entry节点集合------------------");
        //遍历key-value的entry节点集合
        Set<Map.Entry<Integer, String>> entries = hashMap.entrySet();
        for (Map.Entry<Integer, String> entry:entries){
            System.out.println(entry);
        }
        Map<Integer,String> linkedHashMap = new LinkedHashMap<>();
        linkedHashMap.put(null,"5");
        Map<Integer,String> treeMap = new TreeMap<>();//不支持空值，底层是树
        treeMap.put(null,"5");
    }
}
